{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读写图像文件"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 每一个像素都有一个值，不同格式表示像素的方式不同。可以通过一个二维数组创建一个黑色的正方形图像："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0 0]\n",
      " [0 0 0]\n",
      " [0 0 0]]\n"
     ]
    }
   ],
   "source": [
    "img = np.zeros((3,3),dtype=np.uint8)#每个像素都由一个8位整数表示，像素值范围是0-255。\n",
    "print(img)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 用cv2.cvtColor函数将图像转换成（Blue-Green-Red）BGR格式："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]\n",
      "\n",
      " [[0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]\n",
      "\n",
      " [[0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]]\n"
     ]
    }
   ],
   "source": [
    "print(img)#每个像素由一个三元组表示，每个整型向量分别表示一个B、G、R通道。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 通过shape查看图像的结构，返回行和列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 3, 3)\n"
     ]
    }
   ],
   "source": [
    "print(img.shape)#返回的3,3,3分别是行、列、通道数。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 读取一种格式的图像文件，保存为另一种格式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "image = cv2.imread('ImageTest/one.jpg')#将png格式转换为jpg格式\n",
    "cv2.imwrite('ImageTest/one.png',image)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  ...\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]]\n",
      "\n",
      " [[255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  ...\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]]\n",
      "\n",
      " [[255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  ...\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]]\n",
      "\n",
      " ...\n",
      "\n",
      " [[255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  ...\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]]\n",
      "\n",
      " [[255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  ...\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]]\n",
      "\n",
      " [[255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  ...\n",
      "  [255 253 255]\n",
      "  [255 253 255]\n",
      "  [255 253 255]]]\n",
      "(959, 959, 3)\n"
     ]
    }
   ],
   "source": [
    "print(image)\n",
    "print(image.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* BGR和RGB表示的色彩空间相同，，但是字节顺序相反。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* imread()函数参数\n",
    "\n",
    "> IMREAD_ANYCOLOR = 4\n",
    "\n",
    "> IMREAD_ANYDEPTH = 2\n",
    "\n",
    "> IMREAD_COLOR = 1\n",
    "\n",
    "> IMREAD_GRAYSCALE = 0\n",
    "\n",
    "> IMREAD_LOAD_GDAL = 8\n",
    "\n",
    "> IMREAD_UNCHANGED = -1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 例如:将png文件作为灰度图像，又保存为灰度的png图像："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grayImage = cv2.imread('ImageTest/two.png',cv2.IMREAD_GRAYSCALE)\n",
    "cv2.imwrite('ImageTest/two.png',grayImage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[254 254 254 ... 254 254 254]\n",
      " [254 254 254 ... 254 254 254]\n",
      " [254 254 254 ... 254 254 254]\n",
      " ...\n",
      " [254 254 254 ... 254 254 254]\n",
      " [254 254 254 ... 254 254 254]\n",
      " [254 254 254 ... 254 254 254]]\n",
      "(959, 959)\n"
     ]
    }
   ],
   "source": [
    "print(grayImage)\n",
    "print(grayImage.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 图像与原始字节之间的转换"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 8位的灰度图是二维数组，24位的BGR图像是三维数组。如image[0,0]或image[0,0,0]。第一个值代表像素的y坐标或行，0表示顶部；第二个值代表像素的x坐标或列，0表示坐标；第三个值表示颜色通道。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 将含有随机字节的bytearray转换为灰度图像和BGR图像。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "randomByteArray = bytearray(os.urandom(120000))\n",
    "flatNumpyArray = np.array(randomByteArray)\n",
    "\n",
    "grayImage1 = flatNumpyArray.reshape(300,400)\n",
    "cv2.imwrite('ImageTest/randomGray.png',grayImage1)\n",
    "\n",
    "bgrImage = flatNumpyArray.reshape(100,400,3)\n",
    "cv2.imwrite('ImageTest/randomColor.png',bgrImage)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(300, 400)\n",
      "(100, 400, 3)\n"
     ]
    }
   ],
   "source": [
    "print(grayImage1.shape)\n",
    "print(bgrImage.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 将BGR图像在（0,0）处的像素转化为白像素。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img = cv2.imread('ImageTest/image3.jpg')\n",
    "img[0,0] = [255,255,255]\n",
    "cv2.imshow('image',img)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![title](image/img2.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 改变某一坐标的像素值，通过np.array提供的item()函数有3个参数，x,y以及x,y位置的数组索引，该函数返回索引位置的值。还可以通过itemset()函数可设置指定通道的值，有2个参数：一个三元组和索要设定的值。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 将坐标(150,120)的当前蓝色值(127)变为255："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "255\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img = cv2.imread('ImageTest/image3.jpg')\n",
    "print(img.item(150,120,0))\n",
    "\n",
    "img.itemset((150,120,0),255)\n",
    "print(img.item(150,120,0))\n",
    "\n",
    "cv2.imshow('image',img)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![title](image/img1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 操作通道，将指定通道B/G/R的所有值置为0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = cv2.imread('ImageTest/one.jpg')\n",
    "img[:,:,1] = 0#将G值设为0,0表示B，1表示G，2表示R"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  ...\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]]\n",
      "\n",
      " [[255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  ...\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]]\n",
      "\n",
      " [[255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  ...\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]]\n",
      "\n",
      " ...\n",
      "\n",
      " [[255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  ...\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]]\n",
      "\n",
      " [[255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  ...\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]]\n",
      "\n",
      " [[255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  ...\n",
      "  [255   0 255]\n",
      "  [255   0 255]\n",
      "  [255   0 255]]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(img)\n",
    "cv2.imshow('image',img)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 将图像的一部分拷贝到另一部分。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = cv2.imread('ImageTest/image4.jpg')\n",
    "my_roi = img[0:100,0:100]\n",
    "img[300:400,300:400] = my_roi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cv2.imshow('image',img)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![title](image/img3.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 获取图像属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "图像维度为： (2560, 1440, 3)\n",
      "图像像素大小为： 2759043\n",
      "图像格式为： uint8\n"
     ]
    }
   ],
   "source": [
    "img = cv2.imread('ImageTest/image3.jpg')\n",
    "print('图像维度为：',img.shape)#返回图像宽度，高度，通道数\n",
    "print('图像像素大小为：',image.size)#图像像素的大小\n",
    "print('图像格式为：',img.dtype)#图像的数据类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 视频文件的读/写"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* VideoCapture和VideoWriter支持各种格式的视频文件。VideoCapture通过read函数获取新的帧，将图像传递给VideoWriter的write函数，会将图像加到VideoWriter指向的文件中，文件若存在，则被覆盖。VideoWriter构造函数要指定文件名和视频编解码器。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "[[[0 1 0]\n",
      "  [0 1 0]\n",
      "  [0 1 0]\n",
      "  ...\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]\n",
      "\n",
      " [[0 1 0]\n",
      "  [0 1 0]\n",
      "  [0 1 0]\n",
      "  ...\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]\n",
      "\n",
      " [[0 1 0]\n",
      "  [0 1 0]\n",
      "  [0 1 0]\n",
      "  ...\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]\n",
      "\n",
      " ...\n",
      "\n",
      " [[0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  ...\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]\n",
      "\n",
      " [[0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  ...\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]\n",
      "\n",
      " [[0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  ...\n",
      "  [0 0 0]\n",
      "  [0 0 0]\n",
      "  [0 0 0]]]\n",
      "False\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "videoCapture = cv2.VideoCapture('video/video1.avi')\n",
    "fps = videoCapture.get(cv2.CAP_PROP_FPS)\n",
    "size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),\n",
    "       int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))\n",
    "\n",
    "videoWriter = cv2.VideoWriter('video/video2.avi',cv2.VideoWriter_fourcc('I','4','2','0'),fps,size)\n",
    "\n",
    "success,frame = videoCapture.read()\n",
    "\n",
    "print(success)\n",
    "print(frame)\n",
    "\n",
    "while success :\n",
    "    videoWriter.write(frame)\n",
    "    success,frame = videoCapture.read()\n",
    "    \n",
    "print(success)\n",
    "print(frame)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 编解码器的常用选项：\n",
    "\n",
    "> cv2.VideoWriter_fourcc('T','4','2','0')，未压缩的YUV颜色编码，但会产生较大文件，文件扩展名为.avi。\n",
    "\n",
    "> cv2.VideoWriter_fourcc('P','T','M','I')：MPEG-1编码，扩展名为.avi。\n",
    "\n",
    "> cv2.VideoWriter_fourcc(X'','V','I','D')：MPEG-4编码，得到的视频大小为平均值。\n",
    "\n",
    "> cv2.VideoWriter_fourcc('T','H','E','O')：文件扩展名是.ogv。\n",
    "\n",
    "> cv2.VideoWriter_fourcc('F','L','V','I')：Flash视频，扩展名.flv。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 捕获摄像头的帧"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* VideoCapture捕获摄像头的帧流，写入到AVI文件中。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(640, 4)\n"
     ]
    }
   ],
   "source": [
    "cameraCapture = cv2.VideoCapture(0)\n",
    "fps = 30#一个假设\n",
    "\n",
    "size = (int(cameraCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cv2.CAP_PROP_FRAME_HEIGHT))\n",
    "print(size)\n",
    "videoWriter = cv2.VideoWriter('video/video3.avi',cv2.VideoWriter_fourcc('I','4','2','0'),fps,size)\n",
    "\n",
    "success,frame = cameraCapture.read()\n",
    "# print(success)\n",
    "# print(frame)\n",
    "if videoCapture.isOpened():# if videoCapture.read()                                                                                                                                                                                           is true\n",
    "    numFrameRemaining = 100 * fps - 1 #10 seconds video\n",
    "    while success and numFrameRemaining > 0:\n",
    "        videoWriter.write(frame)\n",
    "        success,frame = cameraCapture.read()\n",
    "        numFrameRemaining = -1\n",
    "    cameraCapture.release()\n",
    "    \n",
    "else:\n",
    "    print(\"error\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 当需要同步一组或一个多头摄像头的时候，read()不再适用，可用grad()和retrive()方法代替。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "cameraCapture0 = cv2.VideoCapture(0)\n",
    "cameraCapture1 = cv2.VideoCapture(0)\n",
    "\n",
    "success0 = cameraCapture0.grab()\n",
    "success1 = cameraCapture1.grab()\n",
    "\n",
    "if success0 and success1:\n",
    "    frame0 = cameraCapture0.retrieve()\n",
    "    frame1 = cameraCapture1.retrieve()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 在窗口显示图像"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* imshow()函数可以实现图像显示。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = cv2.imread('ImageTest/image3.jpg')\n",
    "cv2.imshow('image',img)#第一个参数是图像名称，第二个参数是图像本身\n",
    "cv2.waitKey()\n",
    "cv2.destroyAllWindows()#释放创建的所有窗口"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 在窗口显示摄像头帧"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* namedWindow()、imshow()、DestroyWindow()函数指定窗口创建、显示和销毁窗口。waitKey获取键盘输入，setMouseCallback获取鼠标输入、"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "showing camera feed. Click window or press any key to stop\n"
     ]
    }
   ],
   "source": [
    "clicked = False\n",
    "def onMouse(event,x,y,flags,param):\n",
    "    global  clicked#global variable\n",
    "    if event == cv2.EVENT_MOUSEMOVE:\n",
    "        clicked = True\n",
    "        \n",
    "cameraCapture = cv2.VideoCapture(0)\n",
    "cv2.namedWindow('My Window')\n",
    "cv2.setMouseCallback('My window',onMouse)\n",
    "print('showing camera feed. Click window or press any key to stop')\n",
    "success,frame = cameraCapture.read()\n",
    "while success and cv2.waitKey(1 ) == -1 and not clicked:# waitKey return -1 is not click key,waitKey参数为等待键盘触发时间\n",
    "    cv2.imshow('My Window',frame)\n",
    "    success,frame = cameraCapture.read()\n",
    "cv2.destroyWindow('My Window')\n",
    "cameraCapture.release()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "97\n"
     ]
    }
   ],
   "source": [
    "print(ord('a'))# 返回字符的ASCII值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (<ipython-input-3-183add7fa18d>, line 30)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-3-183add7fa18d>\"\u001b[1;36m, line \u001b[1;32m30\u001b[0m\n\u001b[1;33m    def channel(self,value):\u001b[0m\n\u001b[1;37m                            ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import time\n",
    "\n",
    "class CaptureManager(object):\n",
    "    \n",
    "    def __init__(self,capture,previewWindowManager = None,shouldMirrorPreview = False):\n",
    "        \n",
    "        self.previewWindowManager = previewWindowManager\n",
    "        self.shouldMirrorPreview = shouldMirrorPreview\n",
    "        \n",
    "        self._capture = capture\n",
    "        self._channel = 0\n",
    "        self._enteredFrame = False\n",
    "        self._frame = None\n",
    "        self._imageFilename = None\n",
    "        sele._videoFilename = None\n",
    "        self._videoEncoding = None\n",
    "        self._videoWriter = None\n",
    "        \n",
    "        self._startTime = None\n",
    "        self._framesElapsed = None\n",
    "        self._fpsEstimate = None\n",
    "        \n",
    "    @property\n",
    "    def channel(self):\n",
    "        return self._channel\n",
    "    \n",
    "    @channel.setter\n",
    "    def channel(self,value):\n",
    "        if self._channel != value:\n",
    "            self._channel = value\n",
    "            self._frame = None\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
